package io.renren.modules.app.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.vo.output.NextWordVo;
import io.renren.common.vo.output.ReciteWordAggVo;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.avanotes.service.ReciteRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author: xiaomi
 * @date: 2022/2/7
 * @description: WX 单词记录
 */
@RestController
@RequestMapping("wx/reciterecord")
@Api("WX小程序 背单词记录 接口")
public class WXReciteRecordController {

    @Autowired
    private ReciteRecordService reciteRecordService;


    @Login
    @PostMapping("/getAggNumber")
    @ApiOperation("获取背单词记录")
    public R getAggNumber(@RequestAttribute("userId") Integer userId) {
        ReciteWordAggVo aggVo = reciteRecordService.genAggNumberByUserId(userId);
        return R.ok().setData(aggVo);
    }

    @Login
    @PostMapping("/nextWord")
    @ApiOperation("获取下一个单词")
    public R nextWord(@RequestAttribute("userId") Integer userId) {
        NextWordVo nextWordVo = reciteRecordService.nextWord(userId);
        return R.ok().setData(nextWordVo);
    }

    @Login
    @PostMapping("/recordAndNextWord")
    @ApiOperation("记录并获取下一个单词")
    public R recordAndNextWord(@RequestAttribute("userId") Integer userId) {
        NextWordVo nextWordVo = reciteRecordService.recordAndNextWord(userId);
        return R.ok().setData(nextWordVo);
    }

    @Login
    @PostMapping("/searchPageRecordingVoc/{pageIndex}")
    @ApiOperation("根据词汇分页显示视频片段")
    public R searchPageRecordingVoc(@RequestAttribute("userId") Integer userId, @PathVariable("pageIndex") Integer pageIndex) {
        PageUtils page = reciteRecordService.searchPageRecordingVocByUserId(userId, pageIndex);
        return R.ok().setData(page);
    }
}
